#coding: utf-8

from django.http import HttpResponse
from django.shortcuts import render
import RPi.GPIO as GPIO

GPIO.cleanup()
GPIO.setmode(GPIO.BCM)

# Create your models here.
def index(request):
	return render(request, 'index.html')


def gpioset(request):
	gpiovalue = request.GET['a']
	gpionumber = gpiovalue.split('#')[0]
	gpionumber = int(gpionumber)
	gpiostate = gpiovalue.split('#')[1]

	GPIO.setup(gpionumber, GPIO.OUT)

	if gpiostate == 'k':
		GPIO.output(gpionumber, 1)
	elif gpiostate == 'g':
		GPIO.output(gpionumber, 0)

	return HttpResponse(a)